<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/uilibs.jsp"%>
<script src="${res}/js/md5.js" type="text/javascript"></script>

<style type="text/css">

</style>
</head>
<body>
<div class="mini-fit">

    <div style="padding-left:11px;padding-bottom:5px;">
        <div>
            <form id="form" method="post">
                <input name="id" id="id" value="${vo.id}" class="mini-hidden" />
                <table style="font-size:12px;" cellpadding="1"
                            cellspacing="5">
                    <tr>
                        <td style="width:70px;">用户名:</td>
                        <td>
                            <input name="username" id="username" style="width:150px;" required="true" class="mini-textbox" value="${vo.username}" readOnly="readOnly"/>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:70px;">原始密码:</td>
                        <td>
                            <input name="source_password" id="source_password" style="width:150px;" required="true" class="mini-hidden" value="${vo.password}"/>
                            <input name="password" id="password" style="width:150px;" required="true" class="mini-password"/>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:70px;">新密码:</td>
                        <td>
                            <input name="new_password" id="new_password" style="width:150px;" required="true" class="mini-password"/>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:70px;">重复密码:</td>
                        <td>
                            <input name="confrim_password" id="confrim_password" style="width:150px;" required="true" class="mini-password"/>
                        </td>
                    </tr>
                    
                    <tr>
                        <td colspan="2">
                            <a onclick="onOkClick" class="mini-button" style="width:60px;">确认</a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
var form;
$(function(){
    mini.parse();
    form = new mini.Form("form");
});

function onOkClick(){
    form.validate();
    var vo = form.getData(true,false);
    if (form.isValid()) {
    	var src_pwd = mini.get("source_password").getValue();
        var pwd = hex_md5(mini.get("password").getValue());
        var new_password = mini.get("new_password").getValue();
        var confrim_password = mini.get("confrim_password").getValue();
        if(pwd!=src_pwd){
            mini.alert("原始密码错误！");
            return;
        }
        if(new_password!=confrim_password){
            mini.alert("重复密码不一致！");
            return;
        }
        delete vo.source_password;
        delete vo.new_password;
        delete vo.confrim_password;
        vo.password=hex_md5(confrim_password);
        Dao.saveOrUpdate("system_user",vo,function(data){
          if(data){
            mini.alert("密码修改成功，请重新登录！","",function(){
                parent.location.href="${ctx}/system/main/logout";
            });
          } else {
            mini.alert("服务器繁忙，请稍后重试");
          }
        });
    }
}

function onResetClick(e) {
    var form = new mini.Form("#form");
    form.clear();
}

</script>
</body>
</html>